package com.haidechizi.sort;

import java.util.Arrays;

public class QuickSort {

    public static void main(String[] args) {
        int[] arr = new int[]{9, 8, 2, 56, 3, 4, 81, 5, 18, 6};
        quickSort(arr, 0, arr.length - 1);
        System.out.println(Arrays.toString(arr));
    }

    public static void quickSort(int[] arr, int start, int end) {
        if (start >= end) {
            return;
        }
        int position = arr[start];

        int low = start;

        int high = end;
        while (low < high) {
            while (low < high && arr[high] >= position) {
                high--;
            }
            arr[low] = arr[high];
            while (low < high && arr[low] < position) {
                low++;
            }
            arr[high] = arr[low];
        }
        arr[low] = position;
        quickSort(arr, start, low);
        quickSort(arr, low + 1, high);

    }
}
